import { Component, OnInit } from '@angular/core';
import { PlatformLocation } from '@angular/common';
import { CheckloginService} from '../services/checklogin.service';
import {Router} from "@angular/router";
@Component({
  selector: 'app-tab-bar',
  templateUrl: './tab-bar.component.html',
  styleUrls: ['./tab-bar.component.scss']
})
export class TabBarComponent implements OnInit {
  public title: any = '苜蓿草商城';
  public cancel: any = 'assets/cancel/u786.png';
  public more: any = ' assets/more/u742.png';
   // 点击改变商城图标颜色
  public changShopColor: any;
  public changShopShow: any = true;
  // 点击改变购物车图标颜色
  public changShopCarColor: any;
  public changShopCarShow: any = true;
  // 点击改变个人中心图标颜色
  public changMymsgColor: any;
  public changMymsgShow: any = true;
  // 存储当前地址
  public locationUrl: any;
  public URL: any;
  constructor( private location: PlatformLocation, private router: Router) {
    for (const i in this.location) {
      if (i === 'location') {
        this.locationUrl = this.location[i].href;
        break;
      }
    }
  }
  ngOnInit() {
    if ( this.locationUrl === 'http://localhost:4200/tabar/shop') {
        this.title = '苜蓿草商城';
        this.changShopColor = 'green';
        this.changShopShow = false;
    } else  if ( this.locationUrl === 'http://localhost:4200/tabar/shopcar') {
        this.title = '购物车';
        this.changShopCarColor = 'green';
        this.changShopCarShow = false;
    } else  if ( this.locationUrl === 'http://localhost:4200/tabar/mymsg') {
       this.title = '个人中心';
       this.changMymsgColor = 'green';
       this.changMymsgShow = false;
    }
  }
  changeShopColor() {
    if (!localStorage.user) {
      this.router.navigate(['/login']);
    } else {
      if (this.changShopCarColor !== null || this.changMymsgColor !== null) {
        this.changShopCarColor = '';
        this.changMymsgColor = '';
        this.changShopCarShow = true;
        this.changMymsgShow = true;
      }
      this.router.navigate(['/tabar/shop']);
      this.title = '苜蓿草商城';
      this.changShopColor = 'green';
      this.changShopShow = false;
    }
  }
  changeShopCarColor() {
    if (!localStorage.user) {
      this.router.navigate(['/login']);
    } else {
      if (this.changShopColor !== null || this.changMymsgColor !== null) {
        this.changShopColor = '';
        this.changMymsgColor = '';
        this.changMymsgShow = true;
        this.changShopShow = true;
      }
      this.router.navigate(['/tabar/shopcar']);
      this.title = '购物车';
      this.changShopCarColor = 'green';
      this.changShopCarShow = false;
    }
  }
  changeMymsgColor() {
    if (!localStorage.user) {
      this.router.navigate(['/login']);
    } else {
      if (this.changShopCarColor !== null || this.changShopColor !== null) {
        this.changShopCarColor = '';
        this.changShopColor = '';
        this.changShopCarShow = true;
        this.changShopShow = true;
      }
      this.router.navigate(['/tabar/mymsg']);
      this.title = '个人中心';
      this.changMymsgColor = 'green';
      this.changMymsgShow = false;
    }
  }
}
